package business;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;

public class COVReader {
	private BufferedReader reader;
	String[] headers;
	
	public COVReader (String filepath)
	{
		String firstline = null;
		try {
			reader= new BufferedReader(new FileReader( new File (filepath)));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		try {
			firstline = reader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		headers = firstline.split("\t");
	}
	
	public String[] readLine ()
	{
		String line = null;
		try {
			line = reader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if(line == null)
			return null;
		String[] values = line.split("\t");
		return values;
	}
	
	public HashMap<String, String[]> readCOV () //HashMap with a key of individual ID corresponding to an array of values
	{
		HashMap<String, String[]> lines = new HashMap<String, String[]>();
		String[] line = readLine();
		while(line != null)
		{
			lines.put(line[0].substring(0,9),line); //line[0] is the invididual ID, corresponds to string array of entire line
			line = readLine();
		}
		return lines;
	}
	
	public String[] getHeaders ()
	{
		return headers;
	}
	
	public static void main (String[] args)
	{
		COVReader m = new COVReader("C:\\Users\\Lucas\\Desktop\\demo\\demo\\GTEx_5M_185_Dec2012.Eigenvectors.txt");
		HashMap<String, String[]> a = m.readCOV();
		for(String s: a.keySet())
		{
			System.out.println(s);
		}
		System.out.println(a.size());
	}
}
